class ResourcesController < ApplicationController
  # GET /Resources
  # GET /Resources.xml
  def index
    @resources = Resource.all
  end

  # GET /Resources/1
  # GET /Resources/1.xml
  def show
    @resource = Resource.find(params[:id])
  end

  # GET /Resources/new
  # GET /Resources/new.xml
  def new
    @resource = Resource.new
    @categories = Category.all.collect{|x| [x.name,x.id]}
  end

  # GET /Resources/1/edit
  def edit
    @resource = Resource.find(params[:id])
    @categories= Category.all.collect{|x| [x.name,x.id]}
  end

  # POST /Resources
  # POST /Resources.xml
  def create
    @resource = Resource.new(params[:resource])
    if @resource.save
      redirect_to(:action => "index", :notice => 'Resource was successfully created.')
    else
      render :action => "new"
    end
  end

  # PUT /Resources/1
  # PUT /Resources/1.xml
  def update
    @resource = Resource.find(params[:id])
    if @resource.update_attributes(params[:resource])
      redirect_to :action => 'index', :notice => 'Resource was successfully updated.'
    else
      render :action => "edit"
    end
  end

  # DELETE /Resources/1
  # DELETE /Resources/1.xml
  def destroy
    @resource = Resource.find(params[:id])
    @resource.destroy

    redirect_to :action => 'index'
  end
end
